<div class="row subsystem-header">
    <div class="pull-left">
        <span style="font-size: 16px;">系统参数配置</span>
    </div>
</div>
<div class="row subsystem-toolbar">
    <div style="height: 44px; line-height: 44px;display: inline;">
        <span style="height: 30px; line-height: 30px; margin-top: 7px;display: inline"
              class="pull-left">&nbsp;项目：</span>
        <select id="h-dispatch-batch-config-domain-list" class="form-control pull-left"
                style="width: 180px;height: 24px; line-height: 24px; margin-top: 10px;padding: 0px;">
        </select>
    </div>
</div>
<div class="row"
     id="h-dispatch-batch-config-content"
     style="margin-top: 6px;overflow-y: auto">
</div>
<script type="text/javascript">
    var BatchSysConfigObj = {
        onclick: function (configId, configVal, domainId, configDesc) {
            console.debug(configId, configVal, domainId);
            $.Hmodal({
                header: "修改 [ " + configDesc + " ] 参数值",
                height: "300px",
                body: $("#h-dispatch-batch-config-src").html(),
                preprocess: function () {
                    let dispatchObj = $("#h-dispatch-batch-config-form");
                    dispatchObj.find("input[name='config_value']").val(configVal);
                    dispatchObj.find("input[name='domain_id']").val(domainId);
                    dispatchObj.find("input[name='config_id']").val(configId);
                },
                callback: function (hmode) {
                    $.HAjaxRequest({
                        url: "/v1/dispatch/config/user",
                        type: "post",
                        data: $("#h-dispatch-batch-config-form").serialize(),
                        success: function () {
                            $(hmode).remove();
                            BatchSysConfigObj.init(domainId);
                        }
                    })
                }
            })
        },
        init: function (domainId) {
            $("#h-dispatch-batch-config-content").html("");

            $.getJSON("/v1/dispatch/config/sys", {domain_id: domainId}, function (data) {
                $(data).each(function (index, element) {
                    var pdiv = document.createElement("div");
                    pdiv.className = "col-sm-6 col-md-3";

                    var pdiv2 = document.createElement("div");
                    pdiv2.className = "thumbnail";

                    var pimg = document.createElement("img");
                    pimg.setAttribute("src", element.image);
                    pimg.style.height = "128px";
                    pimg.style.width = "128px";

                    var pdiv3 = document.createElement("div");
                    pdiv3.className = "caption";


                    var ph3 = document.createElement("h3");
                    ph3.innerHTML = element.configDesc;

                    var pp = document.createElement("p");
                    pp.innerHTML = element.details;
                    pp.style.minHeight = "60px";
                    pp.style.marginTop = "6px";

                    var pval = document.createElement("span");
                    pval.innerHTML = element.configValue;
                    pval.style.minHeight = "60px";
                    pval.className = "col-sm-12";
                    pval.style.textAlign = "left";
                    pval.style.fontSize = "16px";
                    pval.style.color = "#ff1e02";
                    pval.style.fontWeight = "600";
                    pval.style.verticalAlign = "middle";
                    pval.style.marginBottom = "6px";
                    pval.style.marginTop = "6px";
                    pval.style.border = "#fcfcfc solid 1px";

                    var pbtn = document.createElement("button");
                    pbtn.className = "btn btn-info";
                    pbtn.setAttribute("role", "button");
                    pbtn.innerHTML = "编辑";
                    pbtn.setAttribute("onclick", "BatchSysConfigObj.onclick('" + element.configId + "','" + element.configValue + "','" + domainId + "','" + element.configDesc + "')");

                    pdiv3.appendChild(ph3);
                    pdiv3.appendChild(pp);
                    pdiv3.appendChild(pval);
                    pdiv3.appendChild(pbtn);

                    pdiv2.appendChild(pimg);
                    pdiv2.appendChild(pdiv3);

                    pdiv.appendChild(pdiv2);

                    document.getElementById("h-dispatch-batch-config-content").appendChild(pdiv);
                })
            })
        }
    };

    $(document).ready(function () {
        var hwindow = document.documentElement.clientHeight;
        $("#h-dispatch-batch-config-content").height(hwindow - 139);

        $.getJSON("/v1/auth/domain/self/owner", function (data) {
            var arr = new Array();
            $(data.owner_list).each(function (index, element) {
                var ijs = {};
                ijs.id = element.domain_id
                ijs.text = element.domain_desc
                ijs.upId = "####hzwy23###"
                arr.push(ijs)
            });

            $("#h-dispatch-batch-config-domain-list").Hselect({
                data: arr,
                height: "24px",
                width: "180px",
                value: data.domain_id,
                onclick: function () {
                    console.log('hello world')
                    let cdomainId = $("#h-dispatch-batch-config-domain-list").val();
                    BatchSysConfigObj.init(cdomainId);
                }
            });

            BatchSysConfigObj.init(data.domain_id);
        });
    });

</script>

<script type="text/html" id="h-dispatch-batch-config-src">
    <form id="h-dispatch-batch-config-form">
        <div class="col-sm-12 col-md-12 col-lg-12" style="margin-top: 36px;">
            <span>参数值: </span>
            <input name="config_value" class="form-control" style="width: 100%; height: 30px; line-height: 30px;"/>
        </div>
        <input name="domain_id" style="display: none;"/>
        <input name="config_id" style="display: none;"/>
    </form>
</script>